How much flour do you have ? 6 How much sugar do you have ? 4 You have enough ingredients
When execution gets to the IF
statement, it finds that
FLOUR >= 4 —— true, because 6 >= 4
and
SUGAR >= 2 —— true, because 4 >= 2
Since both sides are true, the two part question gives us TRUE.
AND is used in a logical expression to insist that there is a TRUE on both sides:
this side must be true AND this side must be true
If both sides are true, the entire AND expression is true.
If either side (or both) are false,
the entire AND expression is false.
AND
is called a logical operator
because it combines two true/false values into
a single true/false value.
A compact way of saying what AND
does is:
AND
is used to check that every requirement is met.
Look at the logical expression:
FLOUR >= 4 AND SUGAR >= 2
What will the expression give us if FLOUR
is 2
and SUGAR
is 0?